//
//  GuideCell.m
//  International_Hospital
//
//  Created by 统杰李 on 16/7/11.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "GuideCell.h"
#import "JASidePanelController.h"
#import "Home_ViewController.h"
#import "Left_ViewController.h"

@interface GuideCell ()

@property (nonatomic,strong) UIImageView *imageView;

//侧滑的控制器
@property (nonatomic, strong) JASidePanelController * JASide_ViewController;

@end

@implementation GuideCell

#pragma mark
#pragma mark - 在layoutSubView里面布局子控件
-(void)layoutSubviews{
    [super layoutSubviews];
    //添加子控件
    [self.contentView addSubview:_imageView];
    
    [self.contentView addSubview:_pageControl];
    
    [self.contentView addSubview:_startButton];
    
    CGFloat width = 161;
    CGFloat hight = 40;
    CGFloat x = (self.bounds.size.width - width) * 0.5;
    CGFloat y = self.bounds.size.height * 0.9;
    
    self.pageControl.frame = CGRectMake(x, y, width, hight);
    
    //约束
    [_imageView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    self.startButton.frame = CGRectMake(x, y, width, hight);
    
}

#pragma mark
#pragma mark - 重写set方法
-(void)setImage:(UIImage *)image{
    _image = image;
    self.imageView.image = image;
}

#pragma mark
#pragma mark - 开始按钮的点击方法
-(void)didClickStartButton:(UIButton *)button{
    
    //实例化 JASidePanelController
    self.JASide_ViewController = [[JASidePanelController alloc] init];
    
    //实例化 左侧 Left_ViewController
    self.JASide_ViewController.leftPanel = [[Left_ViewController alloc] init];
    
    //实例化 右侧 Home_ViewController
    Home_ViewController * home_VC = [[Home_ViewController alloc] init];
    
    self.JASide_ViewController.centerPanel = [[Base_NavController alloc] initWithRootViewController:home_VC];
    
    //跳转根控制器
    [UIApplication sharedApplication].keyWindow.rootViewController = self.JASide_ViewController;
}

#pragma mark
#pragma mark - 懒加载
-(UIButton *)startButton{
    if (_startButton == nil) {
        _startButton = [[UIButton alloc]init];
        [_startButton setBackgroundImage:[UIImage imageNamed:@"guideStart"] forState:UIControlStateNormal];
        [_startButton addTarget:self action:@selector(didClickStartButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _startButton;
}

#pragma mark
#pragma mark - 懒加载pageController
-(UIPageControl *)pageControl{
    if (_pageControl == nil) {
        
        _pageControl = [[UIPageControl alloc]init];
        
        _pageControl.numberOfPages = 4;
        
        _pageControl.pageIndicatorTintColor = [UIColor grayColor];
        
        _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    }
    return _pageControl;
}

-(UIImageView *)imageView{
    if (_imageView == nil) {
        
        _imageView = [[UIImageView alloc]init];
        //用户交互开启
        _imageView.userInteractionEnabled = YES;
        
    }
    
    return _imageView;
}

@end
